package ccm.common;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;

import static java.awt.Frame.ICONIFIED;

public interface FreshControlInterface extends WindowListener, WindowStateListener
{
    default void windowOpened(WindowEvent e)
    {
        setNeedFresh(!((e.getNewState()&ICONIFIED)==ICONIFIED));
    }

    void setNeedFresh(boolean needFresh);

    void setNeedFastFresh(boolean needFresh);

    @Override
    default void windowClosing(WindowEvent e)
    {
        setNeedFresh(!((e.getNewState()&ICONIFIED)==ICONIFIED));
    }

    @Override
    default void windowClosed(WindowEvent e)
    {
        setNeedFresh(!((e.getNewState()&ICONIFIED)==ICONIFIED));
    }

    @Override
    default void windowIconified(WindowEvent e)
    {
        setNeedFresh(!((e.getNewState()&ICONIFIED)==ICONIFIED));
    }

    @Override
    default void windowDeiconified(WindowEvent e)
    {
        setNeedFresh(!((e.getNewState()&ICONIFIED)==ICONIFIED));
    }

    @Override
    default void windowActivated(WindowEvent e)
    {
        setNeedFastFresh(true);
        setNeedFresh(!((e.getNewState()&ICONIFIED)==ICONIFIED));
    }

    @Override
    default void windowDeactivated(WindowEvent e)
    {
        setNeedFastFresh(false);
        setNeedFresh(!((e.getNewState()&ICONIFIED)==ICONIFIED));
    }

    @Override
    default void windowStateChanged(WindowEvent e)
    {
        setNeedFresh(!((e.getNewState()&ICONIFIED)==ICONIFIED));
    }
}
